package universityModel.organization;

import universityModel.curriculum.Curriculum;
import universityModel.utils.DutyForDecanat;
import universityModel.lesson.Exam;
import universityModel.lesson.Lesson;
import universityModel.person.Student;
import universityModel.person.Teacher;
import universityModel.utils.ArrayModel;

/**
 *
 * @author Parkhomenko Dmytro
 */

public class Faculty extends EduEstabl implements DutyForDecanat {
    private ArrayModel<Exam> exams = new ArrayModel<Exam>();
    private ArrayModel<Course> courses;
    private ArrayModel<Teacher> teachers = new ArrayModel<Teacher>();
    private final int LEVEL_COUNT = 6;
    

    public Faculty(EstablInfo establInfo, String facultyName) {
        super(establInfo);
        
        courses = new ArrayModel<Course>(LEVEL_COUNT);
        for(int level = 0; level <= LEVEL_COUNT; level++) {
        	courses.add(new Course(level));
        }
    }
    
    @Override
    public void addExam(Exam exam) {
	exams.add(exam);
    }
        
    public void addTeacher(Teacher teacher) {
        teachers.add(teacher);
    }
   
    @Override
    public void addShedult(Curriculum curriculum) {
	//shedults.add(curriculum);
        findGroup(curriculum.getGroup()).setCurriculum(curriculum);
    }
    
    @Override
    public void addLesson(Lesson lesson) {
        ArrayModel<String> groupsNames = lesson.getGroups();
        for(int index = 0; index < groupsNames.size(); index++) {
            findGroup(groupsNames.get(index)).addLesson(lesson);
        }
    }
    
    @Override
    public void addGroup(String group, int level) {
        courses.get(level).addGroup(group);
    }
		
    public ArrayModel<Exam> getExams(String group) {
        ArrayModel<Exam> model = new ArrayModel<Exam>();
        for(int index = 0; index < exams.size(); index++) {
            if(exams.get(index).isGroup(group)) {
                model.add(exams.get(index));
            }
        }
        return new ArrayModel<Exam>(model);//or make clone for Exam!
    }
          	
    @Override
    public Curriculum getCurriculum(String group) {
        return findGroup(group).getCurriculum();
    }
	
    @Override
    public void enrollStudent(Student student) {
    	findGroup(student.getNameGroup()).addStudent(student);
    }
	
    @Override
    public void expallStudent(Student student) {
	findGroup(student.getNameGroup()).delStudent(student);
    }
         
//    public void showAllTeachers() {
//       for(int curr = 0; curr < teachers.size(); curr++) {
//           outputInfo.print("--------------------------------------------");
//           outputInfo.print(teachers.get(curr).toString());
//           outputInfo.print(teachers.get(curr).getProffesionalDescription());
//           outputInfo.print("--------------------------------------------");
//       }
//    }
//    
//    public void showAllStudents() {
//         for(int level = 1; level <= LEVEL_COUNT; level++) {
//             courses.get(level).ShowCourse();
//         }
//    }
    /*
    public void showCurriculum(String group) {
        findGroup(group).showCurriculum();
    }
    
    * 
    */
    /*
    public void showExams(String group) {
        ArrayModel<Exam> am = getExams(group);
        for(int curr = 0; curr < am.size(); curr++) {
            outputInfo.print("--------------------------------------------");
            outputInfo.print(am.get(curr).toString());
            outputInfo.print("--------------------------------------------");
        }
    }

     *
     */
    private ExtendedGroupView findGroup(String  name) {
       for(int level = 1; level <= LEVEL_COUNT; level++) {
           Course currCourse = courses.get(level);
           if(currCourse.isGroup(name)) {
               return currCourse.getGroup(name);
           }
       }
       return new Group("", -1);
   }
}